import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		userInfo: {},
		token:'',
		phonePageShow:false,
		code:'',
		searchInfos:[],
	},
	getters:{
		getUserInfo(state) {
			let infos = uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : {};
			state.userInfo = infos;
			return state.userInfo;
		},
		getToken(state) {
			return state.token;
		},
		getPhonePageShow(state) {
			return state.phonePageShow;
		},
		getSearchInfo(state) {
			let infos = uni.getStorageSync('searchInfos') ? JSON.parse(uni.getStorageSync('searchInfos')) : [];
			state.searchInfos = infos;
			return state.searchInfos;
		}
	},
	mutations: {
		//保存用户信息
		storeLogin(state, payload) {
			state.userInfo = payload;
			//用户信息持久化到storage
			uni.setStorageSync('userInfo', JSON.stringify(payload));
		},
		storeToken(state, payload) {
			state.token = payload;
			//用户信息持久化到storage
			uni.setStorageSync('token', JSON.stringify(payload));
		},
		//清除用户信息
		storeLogout(state) {
			state.userInfo = {};
			//清除storage
			uni.removeStorageSync('userInfo');
		},
		storeTokenOut(state) {
			state.token = '';
			//清除storage
			uni.removeStorageSync('token');
		},
		setPhonePageShow(state,payload) {
			state.phonePageShow = payload;
		},
		// 查询内容
		setSearchInfo(state,payload) {
			state.searchInfos = payload;
			uni.setStorageSync('searchInfos', JSON.stringify(payload));
		}
	},
	actions: {
		
	}
})
export default store